package com.hmyd.hmyd_android.utils;

import com.hmyd.hmyd_android.R;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.controller.UMSocialService;
import com.umeng.socialize.media.MailShareContent;
import com.umeng.socialize.media.QQShareContent;
import com.umeng.socialize.media.QZoneShareContent;
import com.umeng.socialize.media.SinaShareContent;
import com.umeng.socialize.media.SmsShareContent;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.sso.EmailHandler;
import com.umeng.socialize.sso.QZoneSsoHandler;
import com.umeng.socialize.sso.SinaSsoHandler;
import com.umeng.socialize.sso.SmsHandler;
import com.umeng.socialize.sso.UMQQSsoHandler;
import com.umeng.socialize.weixin.controller.UMWXHandler;
import com.umeng.socialize.weixin.media.CircleShareContent;
import com.umeng.socialize.weixin.media.WeiXinShareContent;

import android.app.Activity;
import android.text.TextUtils;

public class DoShare {

	public static void initSocialSDK(Activity context, UMSocialService mController, String title,
			String url, String iconUrl, boolean isSMS) {
		/*
		 * 添加QQ平台
		 */
		UMQQSsoHandler qqHandler = new UMQQSsoHandler(context, "1104617837", "yinRoSbFypECl3pE");

		QQShareContent qqShareContent = new QQShareContent();
		// 设置分享文字
		qqShareContent.setShareContent(title);
		// 设置分享title
		qqShareContent.setTitle(title);
		// 设置分享图片
		if (TextUtils.isEmpty(iconUrl)) {
			qqShareContent.setShareImage(new UMImage(context, R.drawable.ic_launcher));
		} else {
			qqShareContent.setShareImage(new UMImage(context, iconUrl));
		}
		// 设置点击分享内容的跳转链接
		qqShareContent.setTargetUrl(url);
		mController.setShareMedia(qqShareContent);
		qqHandler.addToSocialSDK();

		/*
		 * 添加QQ空间平台(必须有文字和图片)
		 */
		QZoneSsoHandler qzoneHandler = new QZoneSsoHandler(context, "1104617837",
				"yinRoSbFypECl3pE");
		QZoneShareContent qzone = new QZoneShareContent();
		// 设置分享文字
		qzone.setShareContent(title);
		// 设置点击消息的跳转URL
		qzone.setTargetUrl(url);
		// 设置分享内容的标题
		qzone.setTitle(title);
		// 设置分享图片
		if (TextUtils.isEmpty(iconUrl)) {
			qzone.setShareImage(new UMImage(context, R.drawable.ic_launcher));
		} else {
			qzone.setShareImage(new UMImage(context, iconUrl));
		}
		mController.setShareMedia(qzone);
		qzoneHandler.addToSocialSDK();

		/*
		 * 添加微信平台
		 */
		// UMWXHandler wxHandler = new UMWXHandler(context,
		// "wx33b4cfdb882b9379",// 测试key
		// "d4624c36b6795d1d99dcf0547af5443d");
		UMWXHandler wxHandler = new UMWXHandler(context, "wx8982697092015f6c",// 正式key
				"d4624c36b6795d1d99dcf0547af5443d");
		// // 设置微信好友分享内容
		WeiXinShareContent weixinContent = new WeiXinShareContent();
		// 设置分享文字
		weixinContent.setShareContent(title);
		// 设置title
		weixinContent.setTitle(title);
		// 设置分享内容跳转URL
		weixinContent.setTargetUrl(url);
		// 设置分享图片
		if (TextUtils.isEmpty(iconUrl)) {
			weixinContent.setShareImage(new UMImage(context, R.drawable.ic_launcher));
		} else {
			weixinContent.setShareImage(new UMImage(context, iconUrl));
		}
//		weixinContent.setShareImage(new UMImage(context, iconUrl));
		mController.setShareMedia(weixinContent);
		wxHandler.addToSocialSDK();

		/*
		 * 添加微信朋友圈
		 */
		UMWXHandler wxCircleHandler = new UMWXHandler(context, "wx8982697092015f6c",
				"d4624c36b6795d1d99dcf0547af5443d");
		// 设置微信朋友圈分享内容
		CircleShareContent circleMedia = new CircleShareContent();
		circleMedia.setShareContent(title);
		// 设置朋友圈title
		circleMedia.setTitle(title);
		if (TextUtils.isEmpty(iconUrl)) {
			circleMedia.setShareImage(new UMImage(context, R.drawable.ic_launcher));
		} else {
			circleMedia.setShareImage(new UMImage(context, iconUrl));
		}
		circleMedia.setTargetUrl(url);
		mController.setShareMedia(circleMedia);
		wxCircleHandler.setToCircle(true);
		wxCircleHandler.addToSocialSDK();

		// 添加新浪SSO授权
		mController.getConfig().setSsoHandler(new SinaSsoHandler());
		SinaShareContent sinaContent = new SinaShareContent();
		sinaContent.setShareContent(title + url);
		if (TextUtils.isEmpty(iconUrl)) {
			sinaContent.setShareImage(new UMImage(context, R.drawable.ic_launcher));
		} else {
			sinaContent.setShareImage(new UMImage(context, iconUrl));
		}
		sinaContent.setShareImage(new UMImage(context, iconUrl));
		sinaContent.setTargetUrl(url);
		mController.setShareMedia(sinaContent);
		
		if (isSMS == true){
			// 添加短信分享
			SmsHandler smsHandler = new SmsHandler();
			SmsShareContent smsShareContent = new SmsShareContent();
			smsShareContent.setShareContent(title);
			smsHandler.addToSocialSDK();
		} else {
			mController.getConfig().removePlatform(SHARE_MEDIA.SMS);
		}

		// 添加邮箱分享
		EmailHandler emailHandler = new EmailHandler();
		MailShareContent mail = new MailShareContent();
		mail.setShareContent(title);
		emailHandler.addToSocialSDK();
		
		if (isSMS == true) {
			mController.getConfig().setPlatforms(SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE, SHARE_MEDIA.WEIXIN,
					SHARE_MEDIA.WEIXIN_CIRCLE, SHARE_MEDIA.SINA, SHARE_MEDIA.SMS);
		} else if (isSMS == false) {
			mController.getConfig().setPlatforms(SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE, SHARE_MEDIA.WEIXIN,
					SHARE_MEDIA.WEIXIN_CIRCLE, SHARE_MEDIA.SINA);
		}
		mController.openShare(context, false);
	}

}
